package Admin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import java.awt.Color;
import javax.swing.ImageIcon;


public class LoginPanel extends JPanel {
	private JTextField txtAdmin;
	private JButton btnNewButton;
	private JLabel lblId;
	private JLabel lblPw;
	private JPasswordField pwdAdmin;
	private JPanel contentPane;
	private ManageDTO dto;
	private Management management;
	

	/**
	 * Create the panel.
	 */
	public LoginPanel(JPanel contentPane,Management management) {
		setBackground(Color.WHITE);
		setLayout(null);
		add(getTxtAdmin());
		add(getBtnNewButton());
		add(getLblId());
		add(getLblPw());
		add(getPwdAdmin());
		this.contentPane = contentPane;
		this.management = management;
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon("C:\\Users\\이종기\\Desktop\\HTA\\FinalWorkspace\\FinalProjectWeb\\WebContent\\image\\logo.jpg"));
		lblNewLabel.setBounds(36, 57, 759, 302);
		add(lblNewLabel);
		

	}
	private JTextField getTxtAdmin() {
		if (txtAdmin == null) {
			txtAdmin = new JTextField();
			txtAdmin.setText("admin");
			txtAdmin.setBounds(344, 383, 116, 21);
			txtAdmin.setColumns(10);
		}
		return txtAdmin;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("Log In");
			btnNewButton.setForeground(Color.BLACK);
			btnNewButton.setBackground(Color.WHITE);
			btnNewButton.setBounds(472, 382, 97, 53);
			btnNewButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					login();
				}
			});
		}
		return btnNewButton;
	}
	private JLabel getLblId() {
		if (lblId == null) {
			lblId = new JLabel("ID");
			lblId.setBounds(275, 386, 57, 15);
		}
		return lblId;
	}
	private JLabel getLblPw() {
		if (lblPw == null) {
			lblPw = new JLabel("PW");
			lblPw.setBounds(275, 417, 57, 15);
		}
		return lblPw;
	}
	
	private JPasswordField getPwdAdmin() {
		if (pwdAdmin == null) {
			pwdAdmin = new JPasswordField();
			pwdAdmin.setText("admin");
			pwdAdmin.setBounds(344, 414, 116, 21);
		}
		return pwdAdmin;
	}
	

	public void login(){
		MemberVo v = new MemberVo();
		dto = new ManageDTO();
		
		v.setMid(txtAdmin.getText());
		v.setPwd(pwdAdmin.getText());
		
		int c = dto.logincheck(v);
		
		switch(c){
		case 1 : JOptionPane.showMessageDialog(this, "로그인 성공");
			management.loginstate = true;
			management.mntmNewMenuItem_3.setText("Log Out");
			contentPane.removeAll();
			contentPane.add(new MemberPanel(contentPane));
			contentPane.updateUI();
			
		
		
			break;
		case 2 : JOptionPane.showMessageDialog(this, "비밀번호 틀림");
			break;
		case 3 : JOptionPane.showMessageDialog(this, "아이디 없음");
			break;
		case 4 : JOptionPane.showMessageDialog(this, "권한 없음");
			break;
		}
		
		
		
		
		
	}
}
